//
//  ZCRedpackModelContent.m
//
//  Created by   on 16/1/22
//  Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//

#import "ZCRedpackModelContent.h"


NSString *const kZCRedpackModelContentId = @"id";
NSString *const kZCRedpackModelContentMid = @"mid";
NSString *const kZCRedpackModelContentUtime = @"utime";
NSString *const kZCRedpackModelContentSlogan = @"slogan";
NSString *const kZCRedpackModelContentEtime = @"etime";
NSString *const kZCRedpackModelContentFid = @"fid";
NSString *const kZCRedpackModelContentIsactived = @"isactived";
NSString *const kZCRedpackModelContentOpenid = @"openid";
NSString *const kZCRedpackModelContentCash = @"cash";
NSString *const kZCRedpackModelContentCtime = @"ctime";
NSString *const kZCRedpackModelContentIsUsed = @"is_used";
NSString *const kZCRedpackModelContentRedpackCode = @"redpack_code";
NSString *const kZCRedpackModelContentRpId = @"rp_id";
NSString *const kZCRedpackModelContentRandomCode = @"random_code";
NSString *const kZCRedpackModelContentRedpackName = @"redpack_name";


@interface ZCRedpackModelContent ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation ZCRedpackModelContent

@synthesize contentIdentifier = _contentIdentifier;
@synthesize mid = _mid;
@synthesize utime = _utime;
@synthesize slogan = _slogan;
@synthesize etime = _etime;
@synthesize fid = _fid;
@synthesize isactived = _isactived;
@synthesize openid = _openid;
@synthesize cash = _cash;
@synthesize ctime = _ctime;
@synthesize isUsed = _isUsed;
@synthesize redpackCode = _redpackCode;
@synthesize rpId = _rpId;
@synthesize randomCode = _randomCode;
@synthesize redpackname = _redpackname;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.contentIdentifier = [self objectOrNilForKey:kZCRedpackModelContentId fromDictionary:dict];
            self.mid = [self objectOrNilForKey:kZCRedpackModelContentMid fromDictionary:dict];
            self.utime = [self objectOrNilForKey:kZCRedpackModelContentUtime fromDictionary:dict];
            self.slogan = [self objectOrNilForKey:kZCRedpackModelContentSlogan fromDictionary:dict];
            self.etime = [self objectOrNilForKey:kZCRedpackModelContentEtime fromDictionary:dict];
            self.fid = [self objectOrNilForKey:kZCRedpackModelContentFid fromDictionary:dict];
            self.isactived = [self objectOrNilForKey:kZCRedpackModelContentIsactived fromDictionary:dict];
            self.openid = [self objectOrNilForKey:kZCRedpackModelContentOpenid fromDictionary:dict];
            self.cash = [self objectOrNilForKey:kZCRedpackModelContentCash fromDictionary:dict];
            self.ctime = [self objectOrNilForKey:kZCRedpackModelContentCtime fromDictionary:dict];
            self.isUsed = [self objectOrNilForKey:kZCRedpackModelContentIsUsed fromDictionary:dict];
            self.redpackCode = [self objectOrNilForKey:kZCRedpackModelContentRedpackCode fromDictionary:dict];
            self.rpId = [self objectOrNilForKey:kZCRedpackModelContentRpId fromDictionary:dict];
            self.randomCode = [self objectOrNilForKey:kZCRedpackModelContentRandomCode fromDictionary:dict];
            self.redpackname = [self objectOrNilForKey:kZCRedpackModelContentRedpackName fromDictionary:dict];
        
        

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.contentIdentifier forKey:kZCRedpackModelContentId];
    [mutableDict setValue:self.mid forKey:kZCRedpackModelContentMid];
    [mutableDict setValue:self.utime forKey:kZCRedpackModelContentUtime];
    [mutableDict setValue:self.slogan forKey:kZCRedpackModelContentSlogan];
    [mutableDict setValue:self.etime forKey:kZCRedpackModelContentEtime];
    [mutableDict setValue:self.fid forKey:kZCRedpackModelContentFid];
    [mutableDict setValue:self.isactived forKey:kZCRedpackModelContentIsactived];
    [mutableDict setValue:self.openid forKey:kZCRedpackModelContentOpenid];
    [mutableDict setValue:self.cash forKey:kZCRedpackModelContentCash];
    [mutableDict setValue:self.ctime forKey:kZCRedpackModelContentCtime];
    [mutableDict setValue:self.isUsed forKey:kZCRedpackModelContentIsUsed];
    [mutableDict setValue:self.redpackCode forKey:kZCRedpackModelContentRedpackCode];
    [mutableDict setValue:self.rpId forKey:kZCRedpackModelContentRpId];
    [mutableDict setValue:self.randomCode forKey:kZCRedpackModelContentRandomCode];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.contentIdentifier = [aDecoder decodeObjectForKey:kZCRedpackModelContentId];
    self.mid = [aDecoder decodeObjectForKey:kZCRedpackModelContentMid];
    self.utime = [aDecoder decodeObjectForKey:kZCRedpackModelContentUtime];
    self.slogan = [aDecoder decodeObjectForKey:kZCRedpackModelContentSlogan];
    self.etime = [aDecoder decodeObjectForKey:kZCRedpackModelContentEtime];
    self.fid = [aDecoder decodeObjectForKey:kZCRedpackModelContentFid];
    self.isactived = [aDecoder decodeObjectForKey:kZCRedpackModelContentIsactived];
    self.openid = [aDecoder decodeObjectForKey:kZCRedpackModelContentOpenid];
    self.cash = [aDecoder decodeObjectForKey:kZCRedpackModelContentCash];
    self.ctime = [aDecoder decodeObjectForKey:kZCRedpackModelContentCtime];
    self.isUsed = [aDecoder decodeObjectForKey:kZCRedpackModelContentIsUsed];
    self.redpackCode = [aDecoder decodeObjectForKey:kZCRedpackModelContentRedpackCode];
    self.rpId = [aDecoder decodeObjectForKey:kZCRedpackModelContentRpId];
    self.randomCode = [aDecoder decodeObjectForKey:kZCRedpackModelContentRandomCode];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeObject:_contentIdentifier forKey:kZCRedpackModelContentId];
    [aCoder encodeObject:_mid forKey:kZCRedpackModelContentMid];
    [aCoder encodeObject:_utime forKey:kZCRedpackModelContentUtime];
    [aCoder encodeObject:_slogan forKey:kZCRedpackModelContentSlogan];
    [aCoder encodeObject:_etime forKey:kZCRedpackModelContentEtime];
    [aCoder encodeObject:_fid forKey:kZCRedpackModelContentFid];
    [aCoder encodeObject:_isactived forKey:kZCRedpackModelContentIsactived];
    [aCoder encodeObject:_openid forKey:kZCRedpackModelContentOpenid];
    [aCoder encodeObject:_cash forKey:kZCRedpackModelContentCash];
    [aCoder encodeObject:_ctime forKey:kZCRedpackModelContentCtime];
    [aCoder encodeObject:_isUsed forKey:kZCRedpackModelContentIsUsed];
    [aCoder encodeObject:_redpackCode forKey:kZCRedpackModelContentRedpackCode];
    [aCoder encodeObject:_rpId forKey:kZCRedpackModelContentRpId];
    [aCoder encodeObject:_randomCode forKey:kZCRedpackModelContentRandomCode];
}

- (id)copyWithZone:(NSZone *)zone
{
    ZCRedpackModelContent *copy = [[ZCRedpackModelContent alloc] init];
    
    if (copy) {

        copy.contentIdentifier = [self.contentIdentifier copyWithZone:zone];
        copy.mid = [self.mid copyWithZone:zone];
        copy.utime = [self.utime copyWithZone:zone];
        copy.slogan = [self.slogan copyWithZone:zone];
        copy.etime = [self.etime copyWithZone:zone];
        copy.fid = [self.fid copyWithZone:zone];
        copy.isactived = [self.isactived copyWithZone:zone];
        copy.openid = [self.openid copyWithZone:zone];
        copy.cash = [self.cash copyWithZone:zone];
        copy.ctime = [self.ctime copyWithZone:zone];
        copy.isUsed = [self.isUsed copyWithZone:zone];
        copy.redpackCode = [self.redpackCode copyWithZone:zone];
        copy.rpId = [self.rpId copyWithZone:zone];
        copy.randomCode = [self.randomCode copyWithZone:zone];
    }
    
    return copy;
}


@end
